var lod;
var Main = {

    data() {
        return {

            contain: 'ss',
            isLogin: false,
            form: {
                accound: '',
                usercard: '',
                password: '',
            },
            src: 'static/image/1639722052841.jpg'
        }
    },
    methods: {

        handleCommand() {
            this.$message('click on item ');
        },
        onSubmit() {
            let that = this;
            if (this.form.accound == '' || this.form.usercard == '' || this.form.password == '') {
                this.$message({
                    message: '请填写完整',
                    type: 'warning'
                });
            } else {
                axios({
                        method: "post",
                        url: "login",
                        // headers:{"Content-Type":'application/x-www-form-urlencoded;charset=UTF-8','X-Requested-With': 'XMLHttpRequest'},
                        data: {
                            accound: this.form.accound,
                            usercard: this.form.usercard,
                            password: this.form.password,
                        }
                    })
                    .then(function (res) {
                        //接口成功返回结果执行
                        console.log(res.status);
                        if (res.status == '200' && res.data.code == '200') {
                            that.$message({
                                message: '恭喜你，登录成功',
                                type: 'success'
                            });
                            location.reload();
                        } else {
                            that.$message.error(res.data.msg);
                        }
                    })
                    .catch(function (err) {})
            }
        },
        onInitComent() {
            // loading
            let that = this;
            if ($.cookie('userid') != null && $.cookie('tkoen') != null) {
                this.isLogin = true;
                $('.log-sp').text('个人空间');
                $('.set-sp').css('display', 'inline');
                $('.log-btn').text('我的班级');
                $('.reg-btn').text('最新动态');
                $('.el-dropdown-menu').append('<li tabindex="-1" class="el-dropdown-menu__item" command="a">' + $.cookie('user') + '</li><li tabindex="-1" class="el-dropdown-menu__item" command="b">消息通知</li><li tabindex="-1" class="el-dropdown-menu__item" command="c">我的班级</li><li tabindex="-1" class="el-dropdown-menu__item" command="d">退出登录</li>');
                $('.el-dropdown-menu__item').click(function () {
                    
                    switch (this.attributes[2].nodeValue) {
                        case 'd':
                            // that.$message('click on item ' + this.attributes[2].nodeValue);
                            that.exitUser();
                        break;
                    }
                });
            } else {
                
            }
            lod.close();
        },
        onClickLogin() {
            if (this.isLogin) {
                $('.grid-login-content').css('display', 'none');
            } else {
                $('.grid-login-content').css('display', 'block');
            }
        },
        openFullScreen() {
            lod = this.$loading({
                lock: true,
                text: '正在加载...',
                spinner: 'el-icon-loading',
                background: 'hsla(0,0%,100%,.9);'
            });
            this.onInitComent();
        },
        closeLogin() {
            this.form.accound = '';
            this.form.usercard = '';
            this.form.password = '';
            $('.grid-login-content').css('display', 'none');
        },
        exitUser() {
            
            $.removeCookie('user',{ path: '/'});
            $.removeCookie('tkoen',{ path: '/'});
            $.removeCookie('userid',{ path: '/'});
            window.location.reload();
        }
    },
    mounted() {
        this.openFullScreen();
    }
}
var Ctor = Vue.extend(Main);
new Ctor().$mount('#app');